<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>methods、computed</title>
</head>
<body>
    <div id="app">
        <a href="https://cn.vuejs.org/v2/api/index.html#computed">computed的参考文档</a>
        <ul>
            <li v-for="(item,key) in header" :key="key">{{item}}</li>
        </ul>
        <button @click="pushFace('样貌')">添加样貌属性</button>
        <br>
        <h3>computed的使用方式</h3>

        <div>{{firstName}},{{lastName}}</div>

        <div>{{fullName}}</div>
    </div>
    <!-- vue2 -->
    <script src="https://cdn.jsdelivr.net/npm/vue@2.6.14"></script>
    <script>
        var app=new Vue({
            name:"app",
            el:"#app",
            data:{
                header:["身高","体重","年龄","性别"],
                firstName:"jie",
                lastName:"Quan"
            },
            methods:{
                pushFace(face){
                    this.header.push(face)
                }
            },
            computed:{
                //使用方式一
                // fullName(){
                //     return this.firstName+this.lastName;
                // },

                // 使用方式二
                fullName:{
                    set:function(val){
                        this.firstName= "全杰"
                        console.log(val)
                    },
                    get:function(){
                        return this.firstName+this.lastName;
                    }
                }
            }
        })
    </script>

</body>
</html>